package cn.kgc.controller;

import cn.kgc.dto.ResultInfo;
import cn.kgc.pojo.Contact;
import cn.kgc.service.ContactService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
@Api(tags = "添加通讯信息接口")
@RestController
@CrossOrigin
@RequestMapping("/add")
public class AddContactController {
    @Resource
    private ContactService contactService;
    @ApiOperation("添加通讯信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "cname",value = "用户姓名",required = true),
            @ApiImplicitParam(name = "mobile",value = "手机号",required = true),
            @ApiImplicitParam(name = "qq",value = "qq",required = true),
            @ApiImplicitParam(name = "email",value = "email",required = true),
            @ApiImplicitParam(name = "address",value = "地址",required = true),
            @ApiImplicitParam(name = "id",value = "id",required = false)
    })
    @PostMapping( "/addContact")
    public ResultInfo addContact(Contact contact){
        try{
            return new ResultInfo(200,"添加成功",contactService.insertContact(contact));
        }catch (Exception e){
            return new ResultInfo(500,"添加失败",null);
        }
    }
}
